﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ballgame.View;
using Ballgame.Model;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using WindowsGame1.View;

namespace Ballgame.View
{
    class BallView
    {
        Camera camera;
        Texture2D ballTexture;
        Texture2D ram;
        Ballsimulation m_ballSimulation;
        Vector2 Visual;
        Vector2 ramVisual;
        int m_resolution;

        public BallView(Ballsimulation ballSimulation, int resolution) 
        {
            m_resolution = resolution;
            m_ballSimulation = ballSimulation;
            camera = new Camera(resolution);
            
        }
        public void LoadContent(ContentManager Content) 
        {
            ballTexture = Content.Load<Texture2D>("juggeboll");
            ram = Content.Load<Texture2D>("ram");

        }
        public void Draw(SpriteBatch spritebatch)
        {

            Vector2 ramPosition = new Vector2(0.0f, 0.0f);
            int offset = camera.GetOffset();

            Visual = camera.GetVisual(m_ballSimulation.ball.getBallPosition(), offset);
            ramVisual = camera.GetVisual(ramPosition, offset);

            int Ballsize = (int)(m_ballSimulation.ball.ballRadius * m_resolution);
            Rectangle ballRectangle = new Rectangle((int)(Visual.X * 0.9f), (int)(Visual.Y * 0.9f), (int)(Ballsize * 0.9), (int)(Ballsize * 0.9));
            Rectangle ramRectangle = new Rectangle((int)ramVisual.X, (int)ramVisual.Y, m_resolution - offset * 2, m_resolution - offset * 2);
            
            ballRectangle.Offset(offset, offset);
            ramRectangle.Offset(offset, offset);

            spritebatch.Draw(ballTexture, ballRectangle, Color.White);
            spritebatch.Draw(ram, ramRectangle, Color.White);
        }
        public void setGameSize(GraphicsDeviceManager graphics)
        {
            graphics.PreferredBackBufferWidth = m_resolution;
            graphics.PreferredBackBufferHeight = m_resolution;
            graphics.ApplyChanges();
        

        }

    }
}
